package run.bottle.tracea.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerExchangeFilterFunction;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.Objects;

@RestController
public class TraceController {

    @Autowired
    private LoadBalancerExchangeFilterFunction lbFunction;

    @GetMapping("/trace-a")
    public Mono<String> trace() {
        System.out.println("===call trace-a===");

        WebClient webClient = WebClient.builder().baseUrl("http://trace-b")
                .filter(lbFunction)
                .build();

        return webClient.get()
                .uri("/trace-b")
                .retrieve()
                .bodyToMono(String.class);
    }

}
